home *** CD-ROM | disk | FTP | other *** search
- /*****
- *
- * Grant's CGI Framework
- * (Common Grant Interface :-)
- * by Grant Neufeld
- * http://arpp.carleton.ca/grant/mac/grantscgi/
- *
- * ListSTAR.c
- *
- * Standard functions for ListSTAR trigger & action applications.
- *
- * You must call InitListSTARUtil in your application startup.
- * You must install ListSTARAEHandle as the event handler for the 9evt9Lis apple event
- * You must write the function:
- * void CustomListSTARProcess ( LStarHdl theLStarHdl )
- * which is where you will, guess what, do your application specific processing
- * of the ListSTAR stuff.
- *
- * Do not call any functions begining with lower case 'lstar' - you can use any of the
- * others - but read their comments first for details.
- *
- * watch the homepage for future upgrades
- *
- * notice of upgrades will be posted to macwwwtool@arpp1.carelton.ca
- * see http://arpp.carleton.ca/list/macwwwtool.html for details
- *
- *
- * Copyright ©1995,1996 by Grant Neufeld
- *
- * http://arpp.carleton.ca/grant/
- * gneufeld@ccs.carleton.ca
- * grant@acm.org
- *
- * This source may be freely used as long as the copyright notice is kept in the source.
- * I ask that you let me know of any enhancements (read: bug fixes) to this code.
- * I would also like copies of (or discounts on) anything you produce this with, please.
- *
- * See the License and Limited Warranty Agreement for all the legal stuff.
- *
- *****/
-
- #include "MyConfiguration.h"
- #if kCompileWithListSTARCode
-
-
- #include <string.h>
-
- #include "compiler_stuff.h"
- #include "globals.h"
-
- #include "AEFunc.h"
- #include "DebugUtil.h"
- #include "MemoryUtil.h"
- #include "StringUtil.h"
-
- /* ListSTAR.h processes differently for ListSTAR.c,
- this is controlled by defining __LStarSegment__ */
- #define __LStarSegment__ 1
- #include "ListSTAR.h"
- #undef __LStarSegment__
-
-
- /*** CONSTANT DECLARATIONS ***/
-
- /*** LOCAL FUNCTION PROTOTYPES ***/
-
- static void lstarDisposeHandle ( LStarHdl );
-
- static OSErr lstarAEGetParamSpoolFile ( AppleEvent *, AEKeyword, FSSpec *, char *, long );
-
-
- /*** FUNCTIONS ***/
-
- /* This initialization function MUST be called in the startup sequence of
- your application */
- OSErr
- InitListSTARUtil ( void )
- {
- OSErr theErr;
- AEEventHandlerUPP theUPP;
- StringHandle liststarSpoolPath;
-
- /* install the ListSTAR apple event handler */
- theUPP = NewAEEventHandlerProc ( ListSTARAppleEvent );
- theErr = AEInstallEventHandler ( kAEClassStarNine, kAEIDListStarEvent, theUPP, 0L, false );
- if ( theErr != noErr )
- {
- /* liststar AE install failed */
- return theErr;
- }
-
- liststarSpoolPath = GetString ( krsListSTARSpoolPath );
- if ( liststarSpoolPath != NULL )
- {
- HLock ( (Handle)liststarSpoolPath );
-
- /* locate ListSTAR's mail spool folder and set up it's FSSpec.
- OSErr returned ignored */
- theErr = FSMakeFSSpec ( nil, nil, *liststarSpoolPath, &gListSTARSpoolFolder );
-
- HUnlock ( (Handle)liststarSpoolPath );
- ReleaseResource ( (Handle)liststarSpoolPath );
- }
-
- return theErr;
- } /* InitListSTARUtil */
-
-
- #pragma mark -
-
- /* */
- static void
- lstarDisposeHandle ( LStarHdl theLStarHdl )
- {
- my_assert ( theLStarHdl != NULL, "\plstarDisposeHandle: theLStarHdl is NULL" );
-
- if ( (*theLStarHdl)->mailService != NULL )
- {
- DisposePtr ( (Ptr)((*theLStarHdl)->mailService) );
- }
- if ( (*theLStarHdl)->senderName != NULL )
- {
- DisposePtr ( (Ptr)((*theLStarHdl)->senderName) );
- }
- if ( (*theLStarHdl)->senderEmail != NULL )
- {
- DisposePtr ( (Ptr)((*theLStarHdl)->senderEmail) );
- }
- if ( (*theLStarHdl)->mailSubject != NULL )
- {
- DisposePtr ( (Ptr)((*theLStarHdl)->mailSubject) );
- }
- if ( (*theLStarHdl)->regExp != NULL )
- {
- DisposePtr ( (Ptr)((*theLStarHdl)->regExp) );
- }
- if ( (*theLStarHdl)->senderMC != NULL )
- {
- DisposePtr ( (Ptr)((*theLStarHdl)->senderMC) );
- }
- if ( (*theLStarHdl)->senderMCZone != NULL )
- {
- DisposePtr ( (Ptr)((*theLStarHdl)->senderMCZone) );
- }
- if ( (*theLStarHdl)->senderMCEmail != NULL )
- {
- DisposePtr ( (Ptr)((*theLStarHdl)->senderMCEmail) );
- }
-
- DisposeHandle ( (Handle)theLStarHdl );
- } /* lstarDisposeHandle */
-
-
- /** APPLE EVENT SUPPORT **/
- #pragma mark -
-
- #pragma segment AppleEvents
- /* AppleEvent Handler for the ListSTAR 9evt-9Lis event */
- pascal OSErr
- ListSTARAppleEvent ( AppleEvent *theAppleEvent, AppleEvent *TheReply, long Reference )
- {
- OSErr theErr;
- Ptr tempBuffer;
- LStarHdl theLStarHdl;
-
- theLStarHdl = (LStarHdl) MemoryNewHandleClear ( sizeof(LStarRecord), &theErr );
- if ( theLStarHdl == NULL )
- {
- return theErr;
- }
-
- /* store references to the apple event and reply records */
- (*theLStarHdl)->appleEvent = theAppleEvent;
- (*theLStarHdl)->replyEvent = TheReply;
-
- tempBuffer = MemoryNewPtr ( kLStarParamMaxSize, &theErr );
- if ( tempBuffer == NULL )
- {
- DisposeHandle ( (Handle)theLStarHdl );
-
- return theErr;
- }
-
- my_assert ( (HGetState((Handle)theLStarHdl) & kMemoryHandleLockedFlag) == nil,
- "\pListSTARAppleEvent: theLStarHdl is already locked!" );
- HLockHi ( (Handle)theLStarHdl );
-
- /* '----' - direct parameter: mailService */
- theErr = AEGetParamString ( theAppleEvent, kLSTARmailService, &((*theLStarHdl)->mailService),
- (char *)tempBuffer, kLStarParamMaxSize );
-
- /* 's9nm' - senderName */
- theErr = AEGetParamString ( theAppleEvent, kLSTARsenderName, &((*theLStarHdl)->senderName),
- (char *)tempBuffer, kLStarParamMaxSize );
-
- /* 's9em' - senderEmail */
- theErr = AEGetParamString ( theAppleEvent, kLSTARsenderEmail, &((*theLStarHdl)->senderEmail),
- (char *)tempBuffer, kLStarParamMaxSize );
-
- /* 's9sj' - mailSubject */
- theErr = AEGetParamString ( theAppleEvent, kLSTARmailSubject, &((*theLStarHdl)->mailSubject),
- (char *)tempBuffer, kLStarParamMaxSize );
-
- /* 's9re' - regExp */
- theErr = AEGetParamString ( theAppleEvent, kLSTARregExp, &((*theLStarHdl)->regExp),
- (char *)tempBuffer, kLStarParamMaxSize );
-
- /* 's9fn' - mailFile */
- theErr = lstarAEGetParamSpoolFile ( theAppleEvent, kLSTARmailFile, &((*theLStarHdl)->mailFile),
- (char *)tempBuffer, kLStarParamMaxSize );
-
- /* 's9mc' - senderMC */
- theErr = AEGetParamString ( theAppleEvent, kLSTARsenderMC, &((*theLStarHdl)->senderMC),
- (char *)tempBuffer, kLStarParamMaxSize );
-
- /* 's9mz' - senderMCZone */
- theErr = AEGetParamString ( theAppleEvent, kLSTARsenderMCZone, &((*theLStarHdl)->senderMCZone),
- (char *)tempBuffer, kLStarParamMaxSize );
-
- /* 's9me' - senderMCEmail */
- theErr = AEGetParamString ( theAppleEvent, kLSTARsenderMCEmail, &((*theLStarHdl)->senderMCEmail),
- (char *)tempBuffer, kLStarParamMaxSize );
-
- /* don't need the buffer any more */
- DisposePtr ( tempBuffer );
-
- /* ••• do we need to add "MyAEGotRequiredParams" here?? */
-
- /* don't know how to determine difference between action and trigger yet,
- so default to trigger. This can be changed to action by the
- 'CustomListSTARProcess' function */
- (*theLStarHdl)->method = ListSTAR_Trigger;
-
- /* allocate triggerValue */
- (*theLStarHdl)->triggerValue = (long *) MemoryNewPtr ( sizeof(long), NULL );
- if ( (*theLStarHdl)->triggerValue != NULL )
- {
- /* default to failure unless the 'CustomListSTARProcess' function determines success or error */
- *((*theLStarHdl)->triggerValue) = Trigger_failure;
- }
-
- /* this is where the application specific ListSTAR event handling comes into play
- the function "CustomListSTARProcess" must be provided by the user of
- this source code */
- HUnlock ( (Handle)theLStarHdl );
- ProcessIsMoreBusy ();
- CustomListSTARProcess ( theLStarHdl );
- ProcessIsLessBusy ();
-
- my_assert ( (HGetState((Handle)theLStarHdl) & kMemoryHandleLockedFlag) == nil,
- "\pListSTARAppleEvent: theLStarHdl is already locked!" );
- HLock ( (Handle)theLStarHdl );
-
- if ( ((*theLStarHdl)->method == ListSTAR_Trigger) &&
- ((*theLStarHdl)->triggerValue != NULL) )
- {
- /* if the event is a trigger, return the trigger value */
- theErr = AEPutParamPtr ( TheReply, keyDirectObject, typeLongInteger,
- (Ptr)((*theLStarHdl)->triggerValue), sizeof(long) );
- }
- else
- {
- /* otherwise, don't return any data */
- theErr = noErr;
- }
-
- HUnlock ( (Handle)theLStarHdl );
-
- /* deallocate memory */
- lstarDisposeHandle ( theLStarHdl );
-
- return theErr;
- } /* ListSTARAppleEvent */
-
-
- #pragma segment AppleEvents
- /* private function to get an HTTPMethod from a parameter */
- static OSErr
- lstarAEGetParamSpoolFile ( AppleEvent *theAppleEvent, AEKeyword theAEKeyword, FSSpec *theFile, char *tempBuffer, long bufferSize )
- {
- OSErr theErr;
- DescType actualType;
- Size actualSize;
-
- my_assert ( theFile != NULL, "\plstarAEGetParamSpoolFile: theFile ptr is NULL" );
- my_assert ( theAppleEvent != NULL, "\plstarAEGetParamSpoolFile: theAppleEvent ptr is NULL" );
- my_assert ( tempBuffer != NULL, "\plstarAEGetParamSpoolFile: tempBuffer ptr is NULL" );
-
- /* put the message spool file name into the tempBuffer */
- theErr = AEGetParamPtr
- ( theAppleEvent, theAEKeyword, typeChar, &actualType, (Ptr)tempBuffer, bufferSize - 1, &actualSize );
- if ( theErr == noErr )
- {
- my_assert ( actualSize < bufferSize, "\plstarAEGetParamSpoolFile: actual param size too big" );
-
- /* terminate the buffer with a null byte, making it a C format string */
- tempBuffer[actualSize] = nil;
-
- /* convert to pascal format string */
- C2PStr ( tempBuffer );
- /* make an fsspec using the mail spool directory and the tempBuffer as file name */
- theErr = FSMakeFSSpec ( gListSTARSpoolFolder.vRefNum,
- gListSTARSpoolFolder.parID, (StringPtr)tempBuffer, theFile );
- }
-
- return theErr;
- } /* lstarAEGetParamHTTPMethod */
-
-
- #endif /* kCompileWithListSTARCode */
-
- /*** EOF ***/
-